﻿using CompanyManageSystem.DLL;
using CompanyManageSystem.Model;
using CompanyManageSystem.Service;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CompanyManageSystem.UI.Repast
{
    public partial class Frm_PurchaseStorageAdd : BaseXtraForm
    {
        public event EventHandler SaveEvent;

        public Frm_PurchaseStorageAdd()
        {
            InitializeComponent();
            this.BindCheckEdit(gridView1,false,true);
            this.BindRowIndicator(gridView1);
        }

        /// <summary>
        /// 窗体加载完成
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Frm_PurchaseStorageAdd_Load(object sender, EventArgs e)
        {
            RepastService rservice = new RepastService();
            gridControl1.DataSource = rservice.GetAllOrderDetailOnTheDay();
            StallTree.Properties.DataSource = rservice.GetAllStall();
            CanteenTree.Properties.DataSource = rservice.GetAllCanteen();
            repositoryItemSearchLookUpEdit1.DataSource = rservice.GetAllMaterial();
        }

        /// <summary>
        /// 确定
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Btn_OK_Click(object sender, EventArgs e)
        {
            var data = this.GetChecked<PurchaseOrderDetail>(gridView1);

            if (data.Count == 0)
            {
                ShowInfo("请选择采购订货明细!");
                return;
            }

            if (SaveEvent != null)
            {
                SaveEvent(data, new EventArgs());
            }
            this.Close();
        }

        /// <summary>
        /// 取消
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Btn_Cancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Btn_Find_Click(object sender, EventArgs e)
        {
            var name = MaterialName.Text.Trim();
            var code = MaterialCode.Text.Trim();
            Guid? canteenId = null;
            Guid? stallId = null;

            if (!string.IsNullOrEmpty(CanteenTree.EditValue.ToString()))
            {
                canteenId = (Guid)CanteenTree.EditValue;
            }
            if (!string.IsNullOrEmpty(StallTree.EditValue.ToString()))
            {
                stallId = (Guid)StallTree.EditValue;
            }

            var rservice = new RepastService();
            gridControl1.DataSource = rservice.GetOrderDetailByFactor(name,code,stallId,canteenId);
        }

    }
}
